package com.tencent.sr.iris.basic.saas.service.convert;

import com.tencent.sr.iris.user.core.service.interfaces.enums.OrgTagEnum;
import com.tencent.sr.iris.user.core.service.interfaces.response.organ.IrisOrganItemResponse;
import com.tencent.sr.iris.user.core.service.interfaces.response.organ.IrisOrganTreeItem;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;

/**
 * @author nixiaolin
 * @date 2022/9/9 10:34
 */
public class OrgConvert {

    /**
     * 获取组织id和名称map
     * @param organTree
     * @return
     */
    public static Map<Long, String> getOrgMap(List<IrisOrganTreeItem> organTree) {
        if (CollectionUtils.isEmpty(organTree)) {
            return Collections.EMPTY_MAP;
        }
        return organTree.stream().filter(i -> {
            IrisOrganItemResponse group = i.getGroup();
            return group != null && group.getExtDto() != null;
        }).collect(Collectors.toMap(k -> k.getGroup().getGroupId(),
                v -> v.getGroup().getGroupName(), (v1, v2) -> v1));
    }
}
